package common.utils;

import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.repository.query.MongoEntityInformation;
import org.springframework.data.mongodb.repository.support.SimpleMongoRepository;

import java.lang.reflect.ParameterizedType;
import java.util.List;

/**
 * @title
 * @description
 * @usage
 * @copyright Copyright 2014  rrmj Corporation. All rights reserved.
 * @company 上海众多美网络科技有限公司
 * @author weseal
 * @create 2018/4/16
 */
public  class BaseRepositoryImpl<T,ID> extends SimpleMongoRepository<T,ID> implements BaseRepository<T,ID> {


	private MongoOperations mongoOperations;
	private MongoEntityInformation<T,ID> metadata;


	public BaseRepositoryImpl(MongoEntityInformation<T, ID> metadata, MongoOperations mongoOperations) {
		super(metadata, mongoOperations);
		this.mongoOperations = mongoOperations;
		this.metadata = metadata;
	}


	@Override
	public List<T> queryPage(Query query) {
		List<T> lists = mongoOperations.find(query,metadata.getJavaType());
		return lists;
	}

	@Override
	public long count(Query query) {
		return mongoOperations.count(query,metadata.getJavaType());
	}
}
